from flask_login import login_required
from flask import request

from ..base import base
from ..service.SolutionService import *

from exts import success, page_success


@base.route('/api/solution/add', methods=['POST'])
@login_required
def solution_add_api():
    '''
    添加解决方案信息
    :return:
    '''
    solution = request.get_json()
    solution_add(solution)
    return success(solution)


@base.route('/api/solution/update', methods=['POST'])
@login_required
def solution_update_api():
    '''
    更新解决信息
    :return:
    '''
    solution = request.get_json()
    solution_update(solution)
    return success(solution)


@base.route('/api/solution/delete', methods=['POST'])
@login_required
def solution_delete_api():
    '''
    删除解决信息
    :return:
    '''
    solution = request.get_json()
    solution_delete(solution['id'])
    return success(solution['id'])


@base.route('/api/solution/detail', methods=['POST'])
@login_required
def solution_detail_api():
    '''
    查询解决方案信息
    :return:
    '''
    solution = request.get_json()
    return success(solution_get_by_id(solution['id']))


@base.route('/api/solution/page', methods=['POST'])
@login_required
def solution_page_api():
    '''
    分页查询资讯
    :return:
    '''
    solution = request.get_json()
    page = solution_page(solution['pageNum'], solution['pageSize'])
    return page_success(page.total, page.items)


# =================================pc产品方案接口=======================================


@base.route('/api/solution/create', methods=['POST'])
def solution_create_api():
    '''
    新增解决方案信息
    :return:
    '''
    solution = request.get_json()
    solution_add(solution)
    return success(solution)


@base.route('/api/solution/tree', methods=['GET'])
def solution_tree_api():
    '''
    解决方案树形接口
    :return:
    '''
    tree = solution_tree()
    return success(tree)
